December 24, 2018

Complex Function Plot with plotly

  • In this slide we will plot a complex function using plotly library
  • The algorithm can plot function for power with natural numbers

Load Library and Create Data

  • The real domain of the function is between -10 and +10
  • The imaginary domain of the function is between -10i and +10i
#create the domain
x <- seq(-10,10, length = 21)
iy <- seq(-10i,10i, length = 21)
f <- function(x,iy){
    z <- matrix(nrow = length(x), ncol = length(iy))
    for(i in 1:length(x)){
        for(j in 1:length(iy)){
            z[i,j] <- x[i]+iy[j]
        }
    }
    return(z)
}
z <- f(x,iy)

Calculate The Function Output

  • Next we create the function and calculate its output
  • Then we extract the real and imaginary part of the function
  • In the next slide the plot of the function will be shown
#calculate the function
fz <- z^4

#extract the real and imaginary part of the function
fx <- Re(fz)
fiy <- Im(fz)

Plot The Real Part of The Function

Plot The Imaginary Part of The Function

Thank you